
using System.Collections;
using System.Collections.Generic;
using Unity.VisualScripting;
using UnityEngine;

// [CreateAssetMenu(fileName = "CardEffect_AddHpAtkBuff", menuName = "CardSystem/CardEffect_AddHpAtkBuff")]

namespace CardEffects
{
    public class CardEffect_AddHpAtkBuff : BaseCardEffectModule
    {
        public int buff_id { get; set; } = 0;
        public int delta_atk { get; set; } = 0;
        public int delta_hp { get; set; } = 0;
        
        public override void Apply(GameObject card, CardUseInfo useInfo = null)
        {
            var card_comp = card.GetComponent<CardController>();
            
            BdPackage.BdUtils.log($"--- on CardEffect_AddHpAtkBuff, delta_atk: {delta_atk}, delta_hp: {delta_hp}");
            
            var buff_data = ScriptableObject.CreateInstance<BuffData>();

            buff_data.id = buff_id;
            buff_data.className = GetType().ToString();
            buff_data.buffName = "测试1";
            buff_data.description = "测试1 description";
            buff_data.isForever = true;
            buff_data.maxStack = BaseInfoManager.instance.MAX_BUFF_STACK;
            
            // var add_buff_module = ScriptableObject.CreateInstance<BuffEffect_ChangeCardProperty>();
            var add_buff_module = new BuffEffect_ChangeCardProperty();
            add_buff_module.delta_atk = delta_atk;
            add_buff_module.delta_hp = delta_hp;
            buff_data.OnCreate = add_buff_module;
            
            // var remove_buff_module = ScriptableObject.CreateInstance<BuffEffect_ChangeCardProperty>();
            var remove_buff_module = new BuffEffect_ChangeCardProperty();
            remove_buff_module.delta_atk = -delta_atk;
            remove_buff_module.delta_hp = -delta_hp;
            buff_data.OnRemove = remove_buff_module;
            
            // string script_object_path = "ScriptObjects/BuffData__add_atack";
            // var buffData = Resources.Load<BuffData>(script_object_path);
            Debug.Log($"Buff Loaded: {buff_data.name}, buff_name: {buff_data.buffName}, desc: {buff_data.description}");
            // buffInfo.buffData.priority = 10;
            
            for (var i = 0; i < GameController.instance.selected_cards.Count; i++)
            {
                var selected_card_i = GameController.instance.selected_cards[i];    
                
                var buffInfo = new BuffInfo();
                buffInfo.buffData = buff_data;
                buffInfo.curStack = 1;
                buffInfo.target = selected_card_i.gameObject;
                buffInfo.creator = card;
                
                BdPackage.BdUtils.log($"--- {selected_card_i.gameObject.name}[{selected_card_i}] --- 增加buff[{buff_data.buffName}]");

                // TestDamageManager.instance.buffHandle.AddBuff(buffInfo);
                var buff_handle = selected_card_i.GetComponent<BuffHandle>();

                buff_handle.AddBuff(buffInfo);
                // selected_card_i.AddComponent<>()
            }
        }
    }
}

